// pages/dongtai/dongtai.js
Page({
  data: {
    friendFeeds: [
      {
        id: 1,
        name: "田小径",
        avatar: "/pages/zhaopian/田小径.jpg",
        time: "2小时前",
        steps: 8560,
        heartRate: 72,
        bloodPressure: "118/75",
        content: "今天天气真好，晨跑5公里达成！",
        likeCount: 12,
        liked: false
      },
      {
        id: 2,
        name: "猪皮怪",
        avatar: "/pages/zhaopian/猪皮怪.jpg",
        time: "5小时前",
        steps: 12450,
        heartRate: 68,
        bloodPressure: "122/78",
        content: "周末徒步记录，坚持健康生活！",
        likeCount: 24,
        liked: true
      }
    ]
  },

  // 刷新动态
  refreshFeed() {
    wx.showLoading({ title: '刷新中...' });
    setTimeout(() => {
      wx.hideLoading();
      wx.showToast({ title: '已更新', icon: 'success' });
    }, 1000);
  },

  // 点赞动态（修改后）
  likeFeed(e) {
    const id = e.currentTarget.dataset.id;
    const updatedFeeds = this.data.friendFeeds.map(item => {
      if (item.id === id) {
        return {
          ...item,
          liked: !item.liked,
          likeCount: item.liked ? item.likeCount - 1 : item.likeCount + 1
        };
      }
      return item;
    });
    this.setData({ friendFeeds: updatedFeeds });

    // 点赞后 1.5 秒返回首页
    
  },

  // 评论动态（修改后）
  commentFeed(e) {
    const id = e.currentTarget.dataset.id;
    wx.navigateTo({
      url: `/pages/comments/comments?feedId=${id}`,
      // 评论页面返回时也跳转首页
      success: () => {
        // 在评论页面的 onUnload 里也要加 wx.reLaunch
      }
    });
  },

  // 新增：页面卸载时强制返回首页
  onUnload() {
    wx.reLaunch({
      url: '/pages/zhuye/zhuye'
    });
  }
});